package com.sims.service.impl;

import java.util.List;

import com.sims.dao.ISimsTeacherDao;
import com.sims.dao.impl.SimsTeacherDaoImp;
import com.sims.eo.SimsTeacher;
import com.sims.service.ITeacherService;

public class TeacherServiceImp implements ITeacherService {
	ISimsTeacherDao simsTeacherDao = new SimsTeacherDaoImp();

	@Override
	public List<SimsTeacher> getAllSimsTeacher() {
		return simsTeacherDao.getAllSimsTeacher();
	}

	@Override
	public boolean deletSimsTeacherById(Long id) {
		return simsTeacherDao.deletSimsTeacherById(id);
	}

	@Override
	public SimsTeacher getSimsTeacherById(Long id) {
		return simsTeacherDao.getSimsTeacherById(id);
	}

	@Override
	public boolean updateSimsTeacher(SimsTeacher teacher) {
		SimsTeacher teacherdb = getSimsTeacherById(teacher.getId());
		int count = (int) simsTeacherDao.getRowCountByTeacherNumber(teacher
				.getTeacherNumber());
		// 数据库不存在或者不是本条数据
		if (count < 1
				|| (count >= 1 && teacher.getTeacherNumber().equals(
						teacherdb.getTeacherNumber()))) {

			if (teacher.getTeacherName() != null) {
				teacherdb.setTeacherName(teacher.getTeacherName());
			}
			if (teacher.getTeacherNumber() != null) {
				teacherdb.setTeacherNumber(teacher.getTeacherNumber());
			}
			if (teacher.getSex() != null) {
				teacherdb.setSex(teacher.getSex());
			}
			if (teacher.getHeight() != null) {
				teacherdb.setHeight(teacher.getHeight());
			}
			if (teacher.getDepartment() != null) {
				teacherdb.setDepartment(teacher.getDepartment());
			}
			if (teacher.getMajor() != null) {
				teacherdb.setMajor(teacher.getMajor());
			}
			if (teacher.getQqNumber() != null) {
				teacherdb.setQqNumber(teacher.getQqNumber());
			}
			if (teacher.getCellphone() != null) {
				teacherdb.setCellphone(teacher.getCellphone());
			}
			return simsTeacherDao.updateSimsTeacher(teacherdb);
		}

		return false;
	}

	@Override
	public List<SimsTeacher> getAllSimsTeacher(int pageNo, int pageSize) {
		return simsTeacherDao.getAllSimsTeacher(pageNo, pageSize);
	}

	@Override
	public long getRowCount() {
		return simsTeacherDao.getRowCount();
	}

	@Override
	public long createTeacher(SimsTeacher teacher) {
		long id2 = 0;
		int count1 = (int) simsTeacherDao.getRowCountByTeacherNumber(teacher
				.getTeacherNumber());
		if (count1 < 1) {
			return simsTeacherDao.createTeacher(teacher);
		}
		return id2;
	}

	@Override
	public SimsTeacher getSimsTeacherbyTeacherNumber(String teacherNumber) {
		return simsTeacherDao.getSimsTeacherbyTeacherNumber(teacherNumber);
	}

	@Override
	public long getRowCountByTeacherNumber(String teacherNumber) {
		return simsTeacherDao.getRowCountByTeacherNumber(teacherNumber);
	}
}
